/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import java.util.List;
import model.Teacher;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

/**
 *
 * @author Moraes
 */
public class TeacherDAO {

    private SqlSessionFactory sqlSessionFactory;

    public TeacherDAO() {
        this.sqlSessionFactory = MyBatisConnectionFactory.getSqlSessionFactory();
    }

    public Teacher selectById(int pIdTeacher) {
        SqlSession session = sqlSessionFactory.openSession();
        try {
            Teacher teacher = (Teacher) session.selectOne("Teacher.getById", pIdTeacher);
            return teacher;
        } finally {
            session.close();
        }
    }

    public List<Teacher> selectAll() {
        SqlSession session = sqlSessionFactory.openSession();
        List<Teacher> teacherList;
        try {
            teacherList = session.selectList("Teacher.getAll");
            return teacherList;
        } finally {
            session.close();
        }
    }

    public void Insert(Teacher pTeacher) {
        SqlSession session = sqlSessionFactory.openSession();
        try {
            session.insert("Teacher.insert", pTeacher);
            session.commit();
        } finally {
            session.close();
        }
    }
}
